package com.javajun.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;

import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

/**
 * @ClassName: Student
 * @Description: 学生实体类
 * @author: xlm
 * @date: 2018年10月12日
 */
@Entity(name="xlm_student")
public class Student {

	private Integer id;
	// 学号
	private String stuNum;
	// 姓名
	private String name;
	// 性别
	private String sex;
	// 密码
	private String password;
	// 职务
	private String job;
	// 班级
	private Claxx claxx;
	// 主修集合 非持久化，从班级中取出
	private List<MainCourse> mainCourses = new ArrayList<>();
	// 主修成绩集合
	private List<MainGrade> mainGrades = new ArrayList<>();
	
	public Student() {
		super();
	}
	
	// Getters And Setters
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	@Column(length=20)
	public String getStuNum() {
		return stuNum;
	}
	public void setStuNum(String stuNum) {
		this.stuNum = stuNum;
	}
	@Column(length=20)
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@Column(length=20)
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	@ManyToOne(fetch=FetchType.EAGER)
	@NotFound(action=NotFoundAction.IGNORE)
	public Claxx getClaxx() {
		return claxx;
	}
	public void setClaxx(Claxx claxx) {
		this.claxx = claxx;
	}
	@Column(length=10)
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}

	@Column(length=20)
	public String getJob() {
		return job;
	}
	public void setJob(String job) {
		this.job = job;
	}

	@Transient
	public List<MainCourse> getMainCourses() {
		List<MainCourse> mainCourses = new ArrayList<>();
		mainCourses = claxx.getMainCourses();
		return mainCourses;
	}
	@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="student")
	public List<MainGrade> getMainGrades() {
		return mainGrades;
	}
	public void setMainGrades(List<MainGrade> mainGrades) {
		this.mainGrades = mainGrades;
	}

}
